/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package Logica;
import java.io.IOException;
import java.io.Writer;
import javax.json.Json;
import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;
import javax.json.JsonObject;
import javax.json.JsonWriter;
/**
 *
 * @author Diego
 */
public class WSEncoder implements Encoder.TextStream<Coordenadas>{

    @Override
    public void encode(Coordenadas coordenadas, Writer writer) throws EncodeException, IOException {
        JsonObject jsonCoordenadas = Json.createObjectBuilder()
                .add("action", "add")
                .add("x", coordenadas.getx())
                .add("y", coordenadas.gety())
                .build();
        try(JsonWriter jsonWriter = Json.createWriter(writer)){
            jsonWriter.writeObject(jsonCoordenadas);
        }
    }

    @Override
    public void init(EndpointConfig config) {
    }

    @Override
    public void destroy() {
    }
    
}